package com.yijianonghu.controller.wxwebsite.message;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yijianonghu.service.wxwebsite.message.SystemNoticeService;
import com.yijianonghu.util.Constants;
import com.yijianonghu.util.ControllerUtils;
import com.yijianonghu.util.exceptionhandler.ControllerExceptionHandler;
import com.yijianonghu.util.result.MessageCode;
import com.yijianonghu.util.result.Result;

@Controller
@RequestMapping(value=Constants.WXConstants.WX_PREFIX+"message/", method=RequestMethod.POST)
public class SystemNoticeController {
	
	private static final Logger logger=LoggerFactory.getLogger(SystemNoticeController.class);
	
	@Autowired
	private SystemNoticeService systemNoticeService;
	
	@Autowired
	private ControllerExceptionHandler exceptionHandler;
	
	@RequestMapping(value="getSystemNoticeList")
	public @ResponseBody Result getSystemNoticeList(HttpSession session, String orderBy){
		//TODO 系统通知没完成
		Result result=new Result();
		List<Map<String, Object>> list=null;
		try{
			Integer userId=ControllerUtils.getUserId(session);
			list=systemNoticeService.getSystemNotice(userId, orderBy);
		}catch(Exception e){
			exceptionHandler.handleException(logger, "获取系统通知失败！", result, MessageCode.SYSTEM_BUSY, e);
		}
		if(list!=null){
			result.setInfor(list);
			result.setSuccess(true);
		}
		return result;
	}
}
